package PartService;

/**
 * Created by ghost461 on 17-5-3.
 */

import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.ServerSocket;
import java.net.Socket;

public class PartListener {
    private int port = 5000;
    private StringBuilder information;
    private ServerSocket server;
    private Socket socket;
    private Reader reader;
    public StringBuilder updateInfomation() {

        try {
            information = new StringBuilder();
            server = new ServerSocket(port);
            socket = server.accept();
            reader = new InputStreamReader(socket.getInputStream());
            char chars[] = new char[64];
            int len;
            while ((len = reader.read(chars)) != -1) {
                information.append(new String(chars, 0, len));
            }
        }catch (IOException e){
            e.printStackTrace();
        }
        return null;
    }
    public StringBuilder getInformation(){
        return information;
    }
    public void close(){
        try {
            reader.close();
            socket.close();
            server.close();
        }catch (IOException e){
            e.printStackTrace();
        }
    }
}
